home *** CD-ROM | disk | FTP | other *** search
/ Technotools / Technotools (Chestnut CD-ROM)(1993).ISO / lang_c / cug106 / charfun.asm < prev    next >
Assembly Source File  |  1984-06-14  |  8KB  |  346 lines

  1. ;                charfun.asm
  2. ;
  3. ;    Copyright (C) 1980, M J Maney
  4. ;
  5. ;    First created 8/16/80
  6. ;    Last revised 8/28/80 14:45
  7. ;
  8. ;    Tested and installed 8/28/80 14:55
  9. ;
  10. ;    This file contains the definitions for some character
  11. ;    functions, written in assembler for compacteness and performance.
  12. ;    The macros from the "crl.lib" file are used to create these
  13. ;    functions in the BDS "crl" format with minimum pain.
  14. ;
  15.     maclib    crl
  16. ;
  17. ;
  18. BLANK    equ    20H
  19. TAB    equ    09H
  20. NEWLINE    equ    0AH
  21. ;
  22. ;
  23. ; * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  24. ;
  25. ;        functions that operate on a byte and return
  26. ;            a small integer or a character
  27. ;
  28. ;    isalpha        isupper        islower        isdigit
  29. ;    isspace        toupper        tolower
  30. ;
  31. ;        functions that operate on a pair of bytes and
  32. ;            return an integer
  33. ;
  34. ;    atob
  35. ;
  36. ; * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  37. ;
  38. ;
  39.     PROC    ISALPHA
  40.     lda    ARG1
  41.     lxi    h,0
  42.     cpi    'A'
  43.     rc            ;less than 'A'
  44.     cpi    'z'+1
  45.     rnc            ;greater than 'z'
  46.     inx    h
  47.     cpi    'a'
  48.     rnc            ;lower-case alpha, return TRUE
  49.     cpi    'Z'+1
  50.     rc            ;upper-case alpha, return TRUE
  51.     dcx    h
  52.     ret            ;else return FALSE
  53.     PEND    ISALPHA
  54. ;
  55. ;
  56.     PROC    ISUPPER
  57.     lda    ARG1
  58.     lxi    h,0
  59.     cpi    'A'
  60.     rc            ;less than 'A'
  61.     cpi    'Z'+1
  62.     rnc            ;greater than 'Z'
  63.     inx    h
  64.     ret            ;else is upper-case
  65.     PEND    ISUPPER
  66. ;
  67. ;
  68.     PROC    ISLOWER
  69.     lda    ARG1
  70.     lxi    h,0
  71.     cpi    'a'
  72.     rc            ;less than 'a'
  73.     cpi    'z'+1
  74.     rnc            ;greater than 'z'
  75.     inx    h
  76.     ret            ;else is lower case
  77.     PEND    ISLOWER
  78. ;
  79. ;
  80.     PROC    ISDIGIT
  81.     lda    ARG1
  82.     lxi    h,0
  83.     cpi    '0'
  84.     rc            ;less than '0'
  85.     cpi    '9'+1
  86.     rnc            ;greater than '9'
  87.     inx    h
  88.     ret            ;else is decimal digit
  89.     PEND    ISDIGIT
  90. ;
  91. ;
  92.     PROC    ISSPACE
  93.     lda    ARG1
  94.     lxi    h,1
  95.     cpi    BLANK
  96.     rz            ;equals ' '
  97.     cpi    TAB
  98.     rz            ;equals tab
  99.     cpi    NEWLINE
  100.     rz            ;equals newline
  101.     dcx    h
  102.     ret            ;else is non-space
  103.     PEND    ISSPACE
  104. ;
  105. ;
  106.     PROC    TOUPPER
  107.     lda    ARG1
  108.     mov    l,a
  109.     mvi    h,0        ;setup to return character unchanged
  110.     cpi    'a'
  111.     rc            ;less than 'a'
  112.     cpi    'z'+1
  113.     rnc            ;greater than 'z'
  114.     adi    'A'-'a'        ;else is lower-case, convert it
  115.     mov    l,a
  116.     ret
  117.     PEND    TOUPPER
  118. ;
  119. ;
  120.     PROC    TOLOWER
  121.     lda    ARG1
  122.     mov    l,a
  123.     mvi    h,0        ;setup to return character unchanged
  124.     cpi    'A'
  125.     rc            ;less than 'A'
  126.     cpi    'Z'+1
  127.     rnc            ;greater than 'Z'
  128.     adi    'a'-'A'        ;else is upper-case, convert it
  129.     mov    l,a
  130.     ret
  131.     PEND    TOLOWER
  132. ;
  133. ;
  134.     PROC    ATOB
  135.     lda    ARG1
  136.     sbi    '0'
  137.     BC    nogood        ;illegal char below '0'
  138.     cpi    10
  139.     BC    gotit        ;character between '0' and '9'
  140.     sbi    'A' - '0'
  141.     BC    nogood        ;illegal char between '9' and 'A'
  142.     cpi    26
  143.     BC    gotalph        ;character between 'A' and 'Z'
  144.     sbi    'a' - 'A'
  145.     BC    nogood        ;illegal char between 'Z' and 'a'
  146.     cpi    26
  147.     BNC    nogood        ;illegal char above 'z'
  148. gotalph:;have valid alpha, must be offset by 10
  149.     adi    10
  150. gotit:    ;have valid alpha-numeric char, converted value in A
  151.     lxi    h,ARG2
  152.     cmp    m
  153.     BNC    nogood        ;illegal char for specified base
  154.     mov    l,a
  155.     mvi    h,0
  156.     ret
  157. ;
  158. nogood:    ;illegal character or out of range for specified base
  159.     lxi    h,-1
  160.     ret
  161.     PEND    ATOB
  162. ;
  163. ;
  164.     end
  165. /*                csym.lib
  166.  
  167.     Copyright (C) 1980, M J Maney
  168.  
  169.     First created    3/1/80
  170.     Last revised    3/29/80 17:00
  171.  
  172.     This file contains some basic definitions that will be needed, or
  173.     at least useful, to the majority of C programs. Some special
  174.     purpose libraries may assume that this library file is to be
  175.     included in a source file when they are to be used.
  176. */
  177.  
  178. /*        Common symbolic constants */
  179. #define    TRUE 1
  180. #define FALSE 0
  181. #define YES 1        /* note YES is the same as TRUE, and NO is the same */
  182. #define NO 0        /* as FALSE. Sometimes one is clearer than the other */
  183. #define OK 1        /* again, the same as TRUE */
  184. #define ERR -1        /* common, though not universal, signal of distress */
  185. #define FF '\014'
  186. #define    NEWLINE '\n'
  187.  
  188. #define INFILE 0    /* symbols for open() in stdlib */
  189. #define OUTFILE 1
  190. #define IOFILE 2
  191.  
  192. #define DSKBUF 134    /* size of buffer needed for getc/putc */
  193. #define IOBUFSIZ 134    /* same as DSKBUF, but I like this name better */
  194. #define FNAMSIZ 16    /* can hold any legal filename with '\0' */
  195.  
  196. #define EOF -1        /* value getc returns on physical end of file */
  197. #define EOT 0x1A    /* value CP/M uses to delimit end of ascii files */
  198.  
  199. /*    DANGER !! the next line contains a character that the Hazeltine
  200.     does not print, but regards as its 'lead-in', so this will look
  201.     sorta funny on the tube !!! ACT prints it ok */
  202. #define #! ~        /* the C complement operator */
  203.  
  204. #define uint unsigned
  205.  
  206.  
  207. /*    Symbols used for stdlib files, collected togethere here to
  208.     ensure system concistency
  209. */
  210. #define    RAM 0
  211. #define    MAXLINE 132
  212. #define    NULL 0
  213.     /* I prefer the name NIL for a pointer to nothing */
  214. #define NIL 0
  215.  
  216. /*    Symbols for IO devices */
  217. #define CONSOLE 1
  218. #define PRINTER 2
  219. #define READER 3
  220. #define PUNCH 4
  221. #define FILE 100
  222. ret            ;else is non-space
  223.     PEND    ISSPACE
  224. ;
  225. ;
  226.     PROC    TOUPPER
  227.     lda    ARG1
  228.     mov    l,a
  229.     mvi    h,0        ;setup to return character unchanged
  230.     cpi    'a'
  231.     rc            ;less than 'a'
  232.     cpi    'z'+1
  233.     rnc            ;greater than 'z'
  234.     adi    'A'-'a'        ;else is lower-case, convert it
  235.     mov    l,a    To incorporate the changes made by HRM in stdlib1.c
  236.     and stdlib2.c into deff.crl and deff2.crl for BDS C ver 1.31,
  237.     the following sequence of commands was executed.
  238.  
  239.     note: comments are prefaced by "--"
  240.  
  241.     -- eliminate old versions in deff and make room for new
  242.  
  243. clib
  244. o 1 deff
  245. d 1 getc
  246. d 1 putc
  247. d 1 fflush
  248. d 1 sscanf
  249. d 1 sprintf
  250. d 1 _uspr
  251. d 1 fgets
  252. c 1        -- save version of deff with space available
  253. ^C        -- reboot
  254.  
  255.     -- add new versions (plus 1 new function) to deff
  256.  
  257. clib
  258. o 1 deff
  259. o 2 stdlib1
  260. o 3 stdlib2
  261. t 2 1 getc
  262. t 2 1 putc
  263. t 2 1 fflush
  264. t 2 1 ungetc    -- the new one
  265. t 3 1 sscanf
  266. t 3 1 sprintf
  267. t 3 1 _uspr
  268. t 3 1 fgets
  269. c 1        -- permanentize it
  270. ^C        -- reboot
  271.  
  272.     -- add new routines to deff2
  273.  
  274. clib
  275. o 1 deff2
  276. o 2 stdlib2
  277. t 2 1 lprintf
  278. t 2 1 pprintf
  279. t 2 1 lputs
  280. t 2 1 pputs
  281. t 2 1 rgets
  282. t 2 1 lputc
  283. t 2 1 pputc
  284. t 2 1 rgetc
  285. c 1        -- permanentize    it
  286. ^C        -- reboot
  287.  
  288.     -- update process is complete
  289.  
  290.  
  291.  
  292. VOLUME CG6
  293.  
  294. DESCRIPTION:
  295.  
  296. NUMBER    SIZE    NAME        COMMENTS
  297.  
  298.         CATALOG.CG6    CONTENTS OF CP/M VOL. CG6
  299.         HISTORY.CG6    Credits for submissions.
  300. CG6.1    1K    BIOSLB.CRL     A bios modified by Harvey Moran
  301. CG6.2    4K    BIOSLB.MAC
  302. CG6.3    9K    BIOSLB.PRN
  303. CG6.4    8K    BSPAT1-4.DOC    More by Moran on bios tinkering.
  304. CG6.5    3K    CHARFUN.ASM    Assembly version of library char
  305.                 manipulation functions.
  306. CG6.6    3K    CRL.DOC       Macro file to aid in generating 
  307.                 BDS compatible CRL files.
  308. CG6.7    8K    CRL.LIB
  309. CG6.8    2K    CSYM.LIB       Symbol file for above.
  310. CG6.9    1K    DEFFMODS.HRM     Narrative (tutorial) describing
  311.                 The modification of Moran's standard
  312.                 libraries. See STDLIB?.
  313. CG6.10    1K    FACT.MOU      Factorial program written in MOUSE
  314. CG6.13    13K    GRAVT100.C     Graphics for the VT100 in ANSI.
  315. CG6.14    9K    GRAVT100.CRL
  316. CG6.15    3K    IOFUN.ASM     Assembly version of C i/o functions.
  317. CG6.16    5K    MACHINE.ASM    Assembly crl functions, mostly
  318.                 for manipulating blocks of memory
  319. CG6.17    5K    MOUSE.C      Interpreter (originally in Pascal)
  320.                 described in BYTE. Issue date in source
  321. CG6.18    1K    NTOI.C        Small number crunching functions.
  322. CG6.19    1K    OTOI.C
  323. CG6.20    4K    PRVLIB.C     Misc. functions.
  324. CG6.21    5K    QUEUE.C      Functions to impliment FIFO's
  325.                 By Scott Layson
  326. CG6.22    1K    STDEF.C       Deff file for NTOI,OTOI,GRAVT100,
  327.                 STRINGS, UTIL1.
  328. CG6.23    4K    STDIO.DOC       Functions to simulate Unix's i/o
  329.                 redirection. Written under 1.31 and
  330.                 never tested in this form. 
  331. CG6.24    2K    STDIO.LIB
  332. CG6.25    5K    STDIO.SRC
  333. CG6.26    7K    STDLIB1.C     Modified libraries (for ver 1.32 of
  334.                 BDS C) needed with Mouse, WP.C, XTRINS.
  335. CG6.27    20K    STDLIB2.C
  336. CG6.28    4K    STRFUN.ASM    C string functions implemented in
  337.                 assembly for efficiency.
  338. CG6.29    5K    STRINGS.C      String manipulation package.
  339. CG6.30    3K    STRINGS.CRL
  340. CG6.31    2K    SYSTEM.C      Deffs for files listed at STDEF.
  341. CG6.32    1K    TEST.MOU      Test program for MOUSE...causes
  342.                 a bug in this implementation to 
  343.                 show itself.
  344. CG6.33    3K    UTIL1.C       Small functions by Donald Stevens.
  345. CG6.34    1K    XTRINSLB.CRL     Two functions to manipulate bits
  346.                 in